<template>
    <div class="home">
        <div class="carousel">
            <transition name="fade" mode="out-in">
                <div class="slide" :key="currentSlide">
                    <img :src="slides[currentSlide].src" :alt="slides[currentSlide].alt" />
                    <div class="slide-text">
                        <h1>{{ slides[currentSlide].title }}</h1>
                        <p>{{ slides[currentSlide].subtitle }}</p>
                        <router-link to="/about" class="btn">了解更多</router-link>
                    </div>
                </div>
            </transition>
            <button @click="prevSlide" class="prev">&#10094;</button>
            <button @click="nextSlide" class="next">&#10095;</button>
        </div>

        <div class="features container">
            <div class="feature">
                <h2>专业的教师团队</h2>
                <p>我们拥有经验丰富、富有爱心的教师。</p>
            </div>
            <div class="feature">
                <h2>丰富的课程</h2>
                <p>提供多样化的课程，促进孩子全面发展。</p>
            </div>
            <div class="feature">
                <h2>安全的环境</h2>
                <p>我们致力于为孩子们提供一个安全、健康的环境。</p>
            </div>
        </div>
    </div>
</template>

<script>
import exampleImage from '@/assets/example.jpg';
import banner1 from "@/assets/banner1.jpg";
import banner2 from "@/assets/banner2.jpg";
import banner3 from "@/assets/banner3.jpg";

export default {
    name: 'Home',
    data() {
        return {
            currentSlide: 0,
            slides: [
                {
                    src: banner1,
                    alt: '幼儿园活动1',
                    title: '欢迎来到我们的幼儿园',
                    subtitle: '一个充满爱与欢乐的地方'
                },
                {
                    src: banner2,
                    alt: '幼儿园活动2',
                    title: '探索无限可能',
                    subtitle: '激发孩子的创造力'
                },
                {
                    src: banner3,
                    alt: '幼儿园活动3',
                    title: '快乐学习 健康成长',
                    subtitle: '我们与您同行'
                }
            ],
            timer: null
        }
    },
    methods: {
        nextSlide() {
            this.currentSlide = (this.currentSlide + 1) % this.slides.length;
        },
        prevSlide() {
            this.currentSlide = (this.currentSlide - 1 + this.slides.length) % this.slides.length;
        }
    },
    mounted() {
        this.timer = setInterval(this.nextSlide, 5000); // 5秒自动切换
    },
    beforeUnmount() {
        clearInterval(this.timer);
    }
}
</script>

<style scoped>
.carousel {
    position: relative;
    width: 100%;
    height: 400px;
    overflow: hidden;
}

.slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    text-align: center;
    color: white;
}

.slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.slide-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.5);
    padding: 20px;
    border-radius: 10px;
}

.carousel .prev, .carousel .next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -22px;
    color: white;
    font-weight: bold;
    font-size: 18px;
    transition: 0.6s ease;
    border-radius: 0 3px 3px 0;
    user-select: none;
    background-color: rgba(0,0,0,0.3);
    border: none;
}

.carousel .next {
    right: 0;
    border-radius: 3px 0 0 3px;
}

.carousel .prev:hover, .carousel .next:hover {
    background-color: rgba(0,0,0,0.8);
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from, .fade-leave-to {
  opacity: 0;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    background-color: #007bff;
    color: #fff;
    border-radius: 5px;
    margin-top: 10px;
}
.features {
    display: flex;
    justify-content: space-around;
    margin-top: 40px;
}
.feature {
    text-align: center;
    max-width: 30%;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .carousel {
        height: 300px;
    }
    .slide-text h1 {
        font-size: 24px;
    }
    .slide-text p {
        font-size: 14px;
    }
    .features {
        flex-direction: column;
        gap: 20px;
    }
    .feature {
        max-width: 100%;
    }
}
</style>
